<!-- src/components/common/ProductCard.vue -->
<template>
  <el-card 
    :body-style="{ padding: '15px' }" 
    shadow="hover" 
    @click="handleClick"
    class="product-card"
  >
    <div class="product-image">
      <el-image
        :src="product.productImage"
        fit="cover"
        class="image"
      >
        <template #placeholder>
          <div class="image-slot">
            <el-icon><Picture /></el-icon>
          </div>
        </template>
      </el-image>
    </div>
    <div class="product-info">
      <div class="product-title">{{ product.productName }}</div>
      <div class="product-price">¥{{ product.productPrice }}</div>
      <div class="product-location">
        <el-icon><Location /></el-icon>
        <span>{{ product.productLocation }}</span>
      </div>
    </div>
  </el-card>
</template>

<script lang="ts" setup>
import { defineProps, defineEmits } from 'vue'
import { Picture, Location } from '@element-plus/icons-vue'

interface Product {
  productId: number
  productName: string
  productPrice: string
  productImage: string
  productLocation: string
  sales?: number
  comments?: number
}

const props = defineProps<{
  product: Product
}>()

const emit = defineEmits<{
  (e: 'click', productId: number): void
}>()

const handleClick = () => {
  emit('click', props.product.productId)
}
</script>

<style scoped>
.product-card {
  cursor: pointer;
}

.product-image {
  height: 200px;
  overflow: hidden;
  border-radius: 4px;
  margin-bottom: 10px;
}

.image {
  width: 100%;
  height: 100%;
}

.product-info {
  padding: 0 5px;
}

.product-title {
  font-size: 14px;
  color: #333;
  margin-bottom: 8px;
  height: 40px;
  overflow: hidden;
  line-height: 1.4;
}

.product-price {
  font-size: 16px;
  color: #ff5000;
  font-weight: bold;
  margin-bottom: 8px;
}

.product-location {
  display: flex;
  align-items: center;
  font-size: 12px;
  color: #999;
  margin-bottom: 8px;
}

.product-location i {
  margin-right: 3px;
}

/* 图片占位符 */
.image-slot {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  background: #f5f7fa;
  color: #909399;
}

.image-slot .el-icon {
  font-size: 36px;
}
</style>